#ifndef USB_TASK_H
#define USB_TASK_H

#include "main.h"

#define TX_BUF_LENGTH   41        // CV_TX_BUF_NUM

typedef struct
{
  uint8_t Head;//1֡ͷ
  uint8_t state;
  uint8_t id;
  uint8_t armors_num;
  uint8_t is_fire;
  uint8_t back;
  fp32 x;
  fp32 y;
  fp32 z;
  fp32 yaw;
  fp32 vx;
  fp32 vy;
  fp32 vz;
  fp32 v_yaw;
  fp32 r1;
  fp32 r2;
  fp32 dz;
  uint32_t cap_timestamp;
  uint16_t t_offset;
  uint16_t checksum;
  uint8_t shoot_cmd;
  int32_t target;
  uint8_t reserved;
  uint8_t back_state;

  fp32 dif_yaw;
} cv_ctrl_t;

typedef struct
{
  uint8_t Head;           // 1
  uint16_t CRC_16;        // 1
  uint8_t mode;           // 1
  fp32 Linear_Twist_X;    // 4
  fp32 Linear_Twist_Y;    // 4
  fp32 Linear_Twist_Z;    // 4
  fp32 Angular_Twist_X;   // 4
  fp32 Angular_Twist_Y;   // 4
  fp32 Angular_Twist_Z;   // 4
} ld_ctrl_t;

#pragma pack(push, 1)
typedef struct
{
  uint8_t framehead;
  uint8_t detect_color;
  uint16_t ones_own_outpost_HP;
  uint16_t others_outpost_HP;
  uint8_t task_mode;
  uint8_t run_mode;
  uint8_t reset_tracker;
  uint8_t is_play;
  uint8_t change_target;
  uint8_t reserved;
  fp32 roll;
  fp32 pitch;
  fp32 yaw;
  uint8_t game_progress;
  uint16_t stage_remain_time;
  uint16_t remain_HP;
  fp32 dif_yaw;
  uint16_t game_time;
  uint32_t timestamp;
  uint16_t CRC_num;
} stm32_to_pc_t;
#pragma pack(pop)

typedef struct
{
  cv_ctrl_t cv_ctrl;
  ld_ctrl_t ld_ctrl;
  stm32_to_pc_t stm32_to_pc;

  uint8_t tx_buf[39];
  uint16_t CRC_SUM;
} usb_control_t;

extern usb_control_t usb_control;

extern void Transmit_RD(uint8_t *Nano_Buf, usb_control_t *usb_ld_ctrl);
extern void usb_task(void const * argument);

extern cv_ctrl_t *get_cv_point(void);
extern const ld_ctrl_t *get_ld_point(void);
extern void USB_STM32_Tx_To_PC(fp32 roll, fp32 pitch, fp32 yaw, usb_control_t *usb_tx_pc);
extern void PC_Tranmit_32(uint8_t *Nano_Buf, usb_control_t *usb_cv_ctrl);

#endif
